import _ from 'lodash'
import * as turf from '@turf/turf'

export default {
  // 计算两点间角度
  getBearing(point1: any, point2: any) {
    const bearing = turf.bearing(point1, point2)
    return bearing
  },

  // 创建平行点位
  createParallelPoint(line: any, offset: any = 0, distance: any = -90) {
    const point1 = line[0]
    const point2 = line[1]
    const bearing = this.getBearing(point1, point2)
    const point = turf.destination(point1, offset, bearing - distance)
    return point.geometry.coordinates
  },

  // 获取两点之间距离
  getDistance(startPoint: any, endPoint: any) {
    const distance = turf.distance(startPoint, endPoint, { units: 'kilometers' })
    return _.floor(distance * 1000, 1)
  }
}
